/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package filecopier.gui;

import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.BorderLayout;
import java.awt.Dimension;

import filecopier.Singleton;

/**
 *
 * @author david
 */
public class AboutDialog extends JDialog {
    
    private JPanel contentPane = null;
    private JButton okBtn = null;

    public AboutDialog() {
        initialize();
    }
    
    private void initialize() {
        setTitle("About FileCopier");
        setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        setContentPane(getJContentPane());
        
        addWindowListener(new java.awt.event.WindowAdapter() {
            
            @Override
            public void windowClosing(java.awt.event.WindowEvent e) {
                setVisible(false);
            }
        });
        
        addComponentListener(new java.awt.event.ComponentAdapter() {
            
            @Override
            public void componentShown(java.awt.event.ComponentEvent e) {
                Dimension preferredSize = getPreferredSize();
                Dimension actualSize = getSize();
                
                if(actualSize.height < preferredSize.height || actualSize.width < preferredSize.width) {
                    setSize(preferredSize);
                }
            }
        });
        
        this.pack();
        // Call visible after setting the componentListener because if you don't it will not call componentShown
        // when the window first becomes visible.
        setVisible(true);

    }
    
    private JPanel getJContentPane() {
        if(contentPane == null) {
            BorderLayout bl = new BorderLayout();
            bl.setHgap(5);
            bl.setVgap(5);
            contentPane = new JPanel(bl);
            JLabel infoLabel = new JLabel("<HTML><CENTER><B>Version " + Singleton.getInstance().getAppVersion() +
                                          "<BR><BR>by<BR>David Armstrong<BR><BR>" +
                                          "email:<BR>fuhgeddaboutitt@gmail.com</B></CENTER></HTML>");
            JLabel iconLabel = new JLabel(new javax.swing.ImageIcon(Singleton.getInstance().getImage32()));
            JLabel emptyLabel = new JLabel();
            emptyLabel.setPreferredSize(iconLabel.getPreferredSize());
            
            contentPane.add(infoLabel, BorderLayout.CENTER);
            contentPane.add(iconLabel, BorderLayout.WEST);
            contentPane.add(emptyLabel, BorderLayout.EAST);
            contentPane.add(getOkBtn(), BorderLayout.SOUTH);
        }
        return contentPane;
    }
    
    private JButton getOkBtn() {
        if(okBtn == null) {
            okBtn = new JButton("OK");
            okBtn.setMnemonic(java.awt.event.KeyEvent.VK_O);
            okBtn.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent e) {
                    setVisible(false);
                }
            });
        }
        return okBtn;
    }
}
